<?php
use yii\helpers\Html;
use common\components\helpers\Fun;
use doumiaoduo\layer\LayerConfirmWidget;
use doumiaoduo\layer\LayerIframeWidget;
LayerConfirmWidget::widget();
LayerIframeWidget::widget();
?>
<div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height" id="toolbar" data-shelve_url="<?=\common\components\helpers\Fun::url(['goodsskill/shelve'])?>" data-role="<?=Yii::$app->user->identity->role?>">
    <div id="search-area" class="yx-bgf7f7f7 yx-radius5 zx-mg yx-function2 yx-pr0">
        <?= Html::beginForm(Fun::url(['mechanicgoods/index']), 'get', ['enctype' => 'multipart/form-data']) ?>
        <?=\common\components\helpers\Search::dropDownList('cate_name',null,$tree,['label'=>'商品分类','promote'=>'请选择','class'=>'search diy_select_txt'])?>
        <?= \common\components\helpers\Search::textInput('goods_name', null, ['label'=>'商品名称','class' => 'search yx-width150 zx-lh24 yx-ml6']); ?>
        <?= \common\components\helpers\Search::textInput('mechanic_name', null, ['label'=>'机构别名','class' => 'search yx-input-text zx-width150 yx-ml6']); ?>
        <?= \common\components\helpers\Search::submitButton('搜索', ['id'=>'search-handle','class'=>"yx-search yx-radius2"]); ?>
        <?php Html::endForm() ?>
    </div>
  <div class="docs-main zx-mg">
      <table id="tablesaw" class="tablesaw table yx-table1 yx-table3 table-striped with-check"  data-tablesaw-mode="swipe" data-tablesaw-minimap >
       <thead>
            <tr class="yx-bgd2f6ec">
                <th><?=\Yii::t('zhtfrontend','商品名称');?></th>
                <th><?=\Yii::t('zhtfrontend','分类名称');?></th>
                <th><?=\Yii::t('zhtfrontend','库存');?></th>
                <th><?=\Yii::t('zhtfrontend','是否可购买');?></th>
                <th><?=\Yii::t('zhtfrontend','类型');?></th>
                <th><?=\Yii::t('zhtfrontend','上课时间');?></th>
                <th><?=\Yii::t('zhtfrontend','状态');?></th>
                <th><?=\Yii::t('zhtfrontend','操作');?></th>
            </tr>
        </thead>
          <?php if($data):?>
               <?php foreach($data as $item):?>
                  <tr data-id="<?=$item['id']?>">
                      <td><?=$item['name']?></td>
                      <td><?=$item['cate_name']?></td>
                      <td><?=$item['store']?></td>
                      <td><?=$item['is_buy']?></td>
                      <td><?=$item['goods_type']?></td>
                      <td><?=$item['class_time']?></td>
                      <td><?=$item['status_name']?></td>
                      <td><?=$item['mechanicoperate']?></td>
                  </tr>
               <?php endforeach;?>
          <?php endif;?>
    </table>
      <div style="text-align: right"><?= common\components\widgets\GoPager::widget(['pagination' => $pages]) ?></div>
  </div>
</div>

<?php
$js = <<<JS
 layer.config({
        extend: ['skin/customskin/style.css']//加载您的扩展样式
    });
  $(document).on('click','.shows',function(){
    $(this).parents('tr').next().show();
    $(this).attr('class','nones').html('-');
  });
$(document).on('click','.nones',function(){
    $(this).parents('tr').next().hide();
    $(this).attr('class','shows').html('+');
  });

  $(document).on('click','.shelve',function(){
      var _this = $(this);
      var tr = _this.parents('tr');
      var td = _this.parent();
      var id = tr.data('id');
      $.post($('#toolbar').data('shelve_url'), {id:id,type:'skill'},function(data){
          if(data.status == 0){
              layer.msg(data.content,{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
            return false;
          }else {
              if(data.is_shelve == 1){
                  td.html("<span style='color:#0E4DAA;cursor: pointer' title='点击下架' class='shelve'>已上架</span>");
                  tr.next().find('td').eq(5).html("<span style='color:#0E4DAA'>已上架</span>");
              }else{
                   td.html("<span style='color:#ff659a;cursor: pointer' title='点击上架' class='shelve'>下架</span>");
                  tr.next().find('td').eq(5).html("<span style='color:#ff659a'>下架</span>");
              }
          }
          
      });
  });
JS;
$this->registerJS($js);
?>


